#!/bin/sh

n_links=0
n_dirs=0
n_bin=0
n_parms=$#
dir=$HOME

usage(){
	echo ""
}
if [ $n_parms -eq "1" ];
then
	dir=$dir
fi

if [ $n_parms -eq "3" ] || [ $n_parms -eq "5" ];
then
	if [[ "$1" == "-d" ]];
	then
		dir="$2"
	elif [[ "$1" == "-u" ]];
	then
		user="$2"
	elif [[ "$3" == "-d" ]];
	then
		dir="$4"
	elif [ "$3" == "-u" ];
	then
		user="$4"
	else
		usage
	fi
fi

if [ $n_parms -eq "2" ];
then
	if [[ "$1" == "-R" ]];
	then
		com="ls -R $dir"
	else
		com="ls $dir"
	fi
fi

if [ $n_parms -eq "4" ] || [ $n_parms -eq "6" ];
then
	if [[ "$1" == "-R" ]];
	then
		com="ls -R $dir"
		if [[ "$2" == "-d" ]];
		then
			dir="$3"
		elif [["$2" == "-u" ]];
		then
			user="$3"
		
		elif [[ "$4" == "-d" ]];
		then
			dir="$5"
		elif [["$4" == "-u" ]];
		then
			user="$5"
		fi
	elif [[ "$3" == "-R" ]]; 
	then
		com="ls -R $dir"
		if [[ "$1" == "-d" ]];
		then
			dir="$3"
		elif [["$1" == "-u" ]];
		then
			user="$3"
		
		elif [[ "$4" == "-d" ]];
		then
			dir="$5"
		elif [["$4" == "-u" ]];
		then
			user="$5"
		fi
	elif [[ "$5" == "-R" ]];
	then	
		com="ls -R $dir"
		if [[ "$1" == "-d" ]];
		then
			dir="$2"
		elif [["$1" == "-u" ]];
		then
			user="$2"
		elif [[ "$3" == "-d" ]];
		then
			dir="$4"
		elif [["$3" == "-u" ]];
		then
			user="$4"
		fi
	else
		usage
	fi
fi

for ARCHIVO in `ls -R $dir`
do
	if echo $ARCHIVO | grep ":" > /dev/null ; then
		DIRECTORIO=$( echo $ARCHIVO | tr -d [=:=] )
		cd "$DIRECTORIO"
	elif [ -L $ARCHIVO ]; 
	then
		n_links=$(( ++n_links ))
	elif [ -d $ARCHIVO ]; 
	then
		n_dirs=$(( ++n_dirs ))
	elif [ -x $ARCHIVO ]; 
	then
		n_bin=$(( ++n_bin ))
	fi
done

echo "DIRS in $HOME --> $n_dirs"
echo "LINKS in $HOME --> $n_links"
echo "BINS in $HOME --> $n_bin"
echo "# --> $n_parms"
